{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "6a83b8cd-382b-401e-9a52-bf4f95b556e8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import numpy as np\n",
    "liao_array = np.array([[1,2,3],[4,5,6]])\n",
    "liao_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "d31e4ac6-ebce-4895-8982-6042068e27af",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(liao_array)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e25316d1-81de-41ec-a293-edb738356607",
   "metadata": {},
   "source": [
    "指定要进行的操作是沿着什么轴（维度）"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "2c2923da-871c-438c-b9e7-6adff2984ede",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 7, 9])"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(liao_array,axis=0) ### 沿着每一列"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "6f07e337-070d-40aa-91b5-3c20d36ef734",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.ndim ### 获取数组的阶数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "94c8fa7c-e828-4c64-bef5-b0d64d8a29f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6, 15])"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(liao_array,axis=1) ### 沿着行进行计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "c23da217-a016-4a67-9191-3059fc08dfca",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6, 15])"
      ]
     },
     "execution_count": 22,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "np.sum(liao_array,axis=-1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "id": "9df7d235-14b8-4266-a69c-49a5b7310b37",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "21"
      ]
     },
     "execution_count": 24,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.sum()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "id": "f42822e3-bcf9-4de1-92ae-50a7037561de",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([5, 7, 9])"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.sum(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "id": "4c0a74d7-131b-4a1c-ac0c-737ab66aed83",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 6, 15])"
      ]
     },
     "execution_count": 28,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.sum(axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 30,
   "id": "c257515f-7acd-4920-a83a-47af92d88b9c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "720"
      ]
     },
     "execution_count": 30,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.prod()  ### 计算数组中所有元素的乘积"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "id": "5ac2b9dd-105c-4d9e-bb7c-0baf903b2f5c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([ 4, 10, 18])"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.prod(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 34,
   "id": "42923a04-e20f-4b1d-a541-311322d720f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([  6, 120])"
      ]
     },
     "execution_count": 34,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.prod(axis=1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 36,
   "id": "3945c63a-f69b-47c6-923b-a8d68b2ad465",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 36,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.min()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 38,
   "id": "24c11c3d-e9a2-4f54-a0f3-cf443081e70f",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 2, 3])"
      ]
     },
     "execution_count": 38,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.min(axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 40,
   "id": "df4cda01-c085-44ad-be24-7b8f78096548",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1, 4])"
      ]
     },
     "execution_count": 40,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.min(axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 42,
   "id": "ccec5b69-735b-4057-af4e-cf4869c7b21a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "6"
      ]
     },
     "execution_count": 42,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.max()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 44,
   "id": "09d201ca-c1e6-4a42-b7fe-b7b4bc565935",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4, 5, 6])"
      ]
     },
     "execution_count": 44,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.max(axis=0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 46,
   "id": "8e21edb7-ca39-4c3d-b530-b4a1a4453414",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([3, 6])"
      ]
     },
     "execution_count": 46,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.max(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e772e595-b917-4083-aebb-291fd6f50748",
   "metadata": {},
   "source": [
    "### 找回索引位置"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 53,
   "id": "8c657329-f31a-4d6b-93fa-85d3fd884e33",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "0"
      ]
     },
     "execution_count": 53,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.argmin()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 55,
   "id": "c73c3ba4-e85f-41a8-87ce-fdee65c72504",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0, 0], dtype=int64)"
      ]
     },
     "execution_count": 55,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.argmin(axis = 0)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 57,
   "id": "47e1fdc0-ca42-4678-afa6-fe6a18ea00b9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0, 0], dtype=int64)"
      ]
     },
     "execution_count": 57,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.argmin(axis = 1)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 61,
   "id": "f9ff2989-f8fe-4056-aa2a-3b10b06133cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 61,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.argmax()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 63,
   "id": "f992c1bc-b516-4644-976e-d1ac705c44b3",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "3.5"
      ]
     },
     "execution_count": 63,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.mean()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 65,
   "id": "ad379582-d4c4-4b2c-adfe-ae726b5de9cc",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([2.5, 3.5, 4.5])"
      ]
     },
     "execution_count": 65,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.mean(axis=0)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95ddc833-e81c-4144-aaee-1e8aca751f4c",
   "metadata": {},
   "source": [
    "###标准差"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 68,
   "id": "81007445-ff2d-44dd-98c5-7cf431530390",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1.707825127659933"
      ]
     },
     "execution_count": 68,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.std()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 72,
   "id": "f3302d40-2349-4a9e-a2c4-b8f8f712123c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([0.81649658, 0.81649658])"
      ]
     },
     "execution_count": 72,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.std(axis=1)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1f9e3d09-5812-43be-8ac9-42a6cf7fb5f1",
   "metadata": {},
   "source": [
    "### 方差的计算"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 75,
   "id": "0154e10d-7314-4f0c-aa10-baa5d7c8200b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2.9166666666666665"
      ]
     },
     "execution_count": 75,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.var()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 77,
   "id": "65edcd32-23e7-41b9-a9e7-0bfa34eb3477",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[1, 2, 3],\n",
       "       [4, 5, 6]])"
      ]
     },
     "execution_count": 77,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 81,
   "id": "3bb5df1f-3a29-4286-b261-d24842d9cd48",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([[2, 2, 3],\n",
       "       [4, 4, 4]])"
      ]
     },
     "execution_count": 81,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.clip(2,4) ### 用于将数组中的元素裁剪（限定）到指定范围之内"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 83,
   "id": "d4015e25-f98b-4266-88a7-391451a7653a",
   "metadata": {},
   "outputs": [],
   "source": [
    "liao_array = np.array([1.2,3.56,6.41])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 85,
   "id": "d63e4a2d-a194-4a0f-9120-b56fb0204897",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1., 4., 6.])"
      ]
     },
     "execution_count": 85,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.round() ### 对数组的每个元素进行四舍五入，默认到整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 87,
   "id": "da1aeb2e-4f16-470f-b447-be9b14c6999b",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([1.2, 3.6, 6.4])"
      ]
     },
     "execution_count": 87,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "liao_array.round(decimals=1) ### 四舍五入时保留一位小数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "f7ddbc7e-9d86-4a6b-bddb-947d2125f07e",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.12.4"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
